package com.edu.controller;

import com.edu.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:何包蛋
 * @Date :2022/12/4 - 12 - 04 - 13:55
 */

@Controller
public class UserController {

    @RequestMapping("/btn1")
    @ResponseBody
    public Object btn1(@RequestBody String str){
        System.out.println(str);
        return str;
    }
    @RequestMapping("/btn2")
    @ResponseBody
    public Object btn2(@RequestBody User user){
        System.out.println(1111);
        System.out.println(user);
        return user;
    }

    @RequestMapping("/btn3")
    @ResponseBody
    public Object btn3( User user){
        System.out.println(user);
        return "user";
    }

    @RequestMapping("/btn4")
    @ResponseBody
    public Object btn4(@RequestBody List<User> users){
        for(User u :users){
            System.out.println(u);
        }
        return "200";
    }
    @RequestMapping("/btn5")
    @ResponseBody
    public List<User> btn5(HttpSession session){
        List<User> users = new ArrayList();
        users.add(new User(1,"zhangsan","123456",18));
        users.add(new User(2,"cuihua","123456",18));
        users.add(new User(3,"shufen","a123456",29));
        session.setAttribute("users",users);
        return users;
    }
}
